//
//  CTUser.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/5/26.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTUser.h"
#import "CTFile.h"

@implementation CTUser


//判断当前是自己还是其他用户
+(BOOL)isUserSelf:(CTUserItem *)itm
{
    BOOL flag;
    
    NSMutableDictionary * userInfoDic = [CTFile getDicFile:@"userInfo.plist" fromDoc:CTFileDocDocuments fromPath:@"user"];
    NSString * uidStr = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"uid"]];
    
    if ([uidStr isEqualToString:itm.uid] == YES) {
        flag = YES;
    }else{
        flag = NO;
    }
    
    return flag;
}

+(CTUserItem *)userInfo
{
    CTUserItem * itm;
    
    if ([CTFile isExistFile:@"userInfo.plist" doc:CTFileDocDocuments path:@"user"] == YES) {
        
        NSMutableDictionary * userInfoDic = [CTFile getDicFile:@"userInfo.plist" fromDoc:CTFileDocDocuments fromPath:@"user"];
        
        itm = [[CTUserItem alloc] init];
        itm.created_at = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"created_at"]];
        itm.follow_me = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"follow_me"]];
        itm.followers_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"followers_count"]];
        itm.following = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"following"]];
        itm.friends_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"friends_count"]];
        itm.group_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"group_count"]];
        itm.mine_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"mine_count"]];
        itm.modified_name_at = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"modified_name_at"]];
        itm.name = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"name"]];
        itm.profile_image_url = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"profile_image_url"]];
        itm.profile_image_url_thumb = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"profile_image_url_thumb"]];
        itm.sign = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"sign"]];
        itm.uid = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"uid"]];
        itm.verified = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified"]];
        itm.verified_reason = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified_reason"]];
        itm.gender = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"gender"]];
        itm.public_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"public_count"]];
        itm.verified_shop = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified_shop"]];
        itm.verified_weibo = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified_weibo"]];
        
    }
    return itm;
}

+(CTUserItem *)otherUserInfo
{
    CTUserItem * itm;
    
    if ([CTFile isExistFile:@"otherUserInfo.plist" doc:CTFileDocDocuments path:@"user"] == YES) {
        
        NSMutableDictionary * userInfoDic = [CTFile getDicFile:@"otherUserInfo.plist" fromDoc:CTFileDocDocuments fromPath:@"user"];
        
        itm = [[CTUserItem alloc] init];
        itm.created_at = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"created_at"]];
        itm.follow_me = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"follow_me"]];
        itm.followers_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"followers_count"]];
        itm.following = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"following"]];
        itm.friends_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"friends_count"]];
        itm.group_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"group_count"]];
        itm.mine_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"mine_count"]];
        itm.modified_name_at = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"modified_name_at"]];
        itm.name = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"name"]];
        itm.profile_image_url = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"profile_image_url"]];
        itm.profile_image_url_thumb = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"profile_image_url_thumb"]];
        itm.sign = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"sign"]];
        itm.uid = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"uid"]];
        itm.verified = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified"]];
        itm.verified_reason = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified_reason"]];
        itm.gender = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"gender"]];
        itm.public_count = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"public_count"]];
        itm.verified_shop = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified_shop"]];
        itm.verified_weibo = [NSString stringWithFormat:@"%@",[userInfoDic objectForKey:@"verified_weibo"]];
        
    }
    return itm;
}

//当前是否是认证用户
+(BOOL)isUserVip:(CTUserItem *)itm
{
    BOOL flag;
    
    if ([itm.verified isEqualToString:@"0"]) {
        flag = NO;
    }else{
        flag = YES;
    }
    
    return flag;
}



//当前用户类型
//目前只用于第三方第一次登陆，并注册的时候
//new:新用户（还未完成注册）  reged:老用户（已完成注册过）
+(CTUserType)userType
{
    CTUserType type;
    NSString * typeStr = [CTFile getFile:@"userType.text" fromDoc:CTFileDocDocuments fromPath:@"user"];
    if ([typeStr isEqualToString:@"new"])type = CTUserTypeNew;
    else type = CTUserTypeReged;
    return type;
}


//用户的用户名（手机号）
+(NSString *)userPhoneNumber
{
    NSString * phoneNumberStr = [CTFile getFile:@"userPhoneNumber.text" fromDoc:CTFileDocDocuments fromPath:@"user"];
    
    return phoneNumberStr;
}


//用户是否注册
//目前只用于验证界面
//1: 注册    0:未注册
+(NSString *)userCreated
{
    NSString * createdStr = [CTFile getFile:@"userCreated.text" fromDoc:CTFileDocDocuments fromPath:@"user"];
    
    return createdStr;
}

@end
